package com.example.demo.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.example.demo.configuration.AliyunOssConfig;
import com.example.demo.controller.bean.Result;
import com.example.demo.dto.ClothingRequestDTO;
import com.example.demo.dto.QuestionBankRequestDTO;
import com.example.demo.mapper.entity.Clothing;
import com.example.demo.mapper.entity.CouponsView;
import com.example.demo.mapper.entity.QuestionBank;
import com.example.demo.mapper.entity.Student;
import com.example.demo.service.QuestionBankManageService;
import com.example.demo.utils.PageBo;
import com.example.demo.utils.PageVo;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RequestMapping("questionBankManage")
@Api(value = "題庫管理接口", tags = {"題庫管理接口"})
@RestController
@Slf4j
public class QuestionBankManageController {
    @Autowired
    private QuestionBankManageService service;

    @ResponseBody
    @ApiOperation(value = "获取題庫列表接口")
    @RequestMapping(value = "getQuestionBankList", method = {RequestMethod.POST})
    public Result<PageVo<QuestionBank>> getQuestionBankList(@RequestBody PageBo pageBo) {
        PageVo<QuestionBank> list = service.getQuestionBankList(pageBo);
        return Result.ok(list);
    }

    @ResponseBody
    @ApiOperation(value = "搜索題庫列表接口")
    @RequestMapping(value = "searchQuestionBank", method = {RequestMethod.POST})
    public Result<PageVo<QuestionBankRequestDTO>> getListSearch(@RequestBody QuestionBankRequestDTO request) {
        PageBo pageBo = new PageBo();
        pageBo.setPageNum(request.getPageNum());
        pageBo.setPageSize(request.getPageSize());

        List<QuestionBank> list = service.searchQuestionBankList(request);
        PageVo<QuestionBankRequestDTO> logs = new PageVo<>(pageBo,list);

        return Result.ok(logs);
    }

    @ApiOperation(value = "新增題庫")
    @PostMapping("/addQuestionBank")
    public Result<String> uploadCommodity(@RequestBody QuestionBank request) {
        System.out.println("新增題庫前端傳入數據："+request);
        // 获取当前会话账号id
        int userId = StpUtil.getLoginIdAsInt();
        request.setCreateBy(userId);
        return service.addQuestionBank(request);
    }

    @ResponseBody
    @ApiOperation("修改題庫接口")
    @RequestMapping(value = "updateQuestionBank", method = {RequestMethod.POST})
    public Result<String> updateQuestionBank(@RequestBody QuestionBank request) {
        return service.updateQuestionBank(request);
    }

    @ResponseBody
    @ApiOperation("删除題庫接口")
    @RequestMapping(value = "deleteQuestionBank", method = {RequestMethod.POST})
    public Result<String> deleteQuestionBank(@RequestBody QuestionBank request) {
        return service.deleteQuestionBank(request);
    }

    @ResponseBody
    @ApiOperation("批量删除接口")
    @RequestMapping(value ="batchDeleteQuestionBank", method = {RequestMethod.POST})
    public Result<String> deleteList(@RequestBody List<QuestionBank> requestList) {
        return service.batchDeleteQuestionBank(requestList);
    }

    @GetMapping("/getBankList")
    @ResponseBody
    public Result<List<QuestionBank>> getBankList(){
        List<QuestionBank> list = service.getBankList();
        return Result.ok(list);
    }
}
